<form id="user-form" lay-filter="user-form" class="layui-form layui-form-pane" style="padding: 15px 15px 0px 15px;height: 100%">
	<div style="height: 80%;">
		<div id="rolebox" style="height: 100%;"></div>
	</div> 
	<div class="layui-form-item model-form-footer">
        <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog"><i class="layui-icon">&#x1006;</i> 取消</button>
        <button class="layui-btn" lay-filter="setrole-form-submit" lay-submit><i class="layui-icon">&#xe605;</i> 保存</button>
    </div>
</form>

<script th:inline="javascript">
/*<![CDATA[*/
    layui.use(['layer', 'jquery', 'form', 'checkbox', 'sadmin'], function () {
        var $ = layui.$ //重点处
        var form = layui.form;
        var checkbox = layui.checkbox;
        var sadmin = layui.sadmin;

        var checkRoleArr = [];
        var data = JSON.parse([[${roleList}]]);
        console.log(data);
        $("#rolebox").children("li").remove();
        checkbox({
            elem: "#rolebox"
            , nodes: data
            , click: function (node) {
                console.log("点击", node);
                checkRoleArr.push(node.id);
            }
            , del: function (node) {
                console.log("删除", node);
                return true;
            }
        });
        
     	// 表单提交事件
        form.on('submit(setrole-form-submit)', function (data) {
        	var data = {userPid: sadmin.getTempData('userPid'), rolePids: checkRoleArr.join(",")};
            layer.load(2);
            $.post('/system/roleuser/saveUserRole', data, function (result) {
                layer.closeAll('loading');
                layer.msg(result.msg);
                sadmin.finishPopupCenter();
            });
            return false;
        });
    });
/*]]>*/
</script>